import 'package:cook_dinner/pages/login/login.dart';
import 'package:flutter/material.dart';
import 'package:cook_dinner/config/include.dart';

class AppLocation extends StatefulWidget {
  const AppLocation({Key? key}) : super(key: key);

  @override
  State<AppLocation> createState() => _AppLocationState();
}

class _AppLocationState extends State<AppLocation> {
  int currentPage = 0;
  PageController pageController = PageController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          PageView.builder(
            controller: pageController,
            onPageChanged: (int index) {
              setState(() {
                currentPage = index;
              });
            },
            itemCount: 3,
            itemBuilder: (BuildContext context, int index) {
              return Stack(
                children: [
                  Image.asset(
                    "assets/images/guide.jpg",
                    width: HYSizeFit.screenWidth,
                    height: HYSizeFit.screenHeight + HYSizeFit.statusHeight,
                    fit: BoxFit.fill,
                  ),
                ],
              );
            },
          ),
          Positioned(
            bottom: 185.rpx,
            left: HYSizeFit.screenWidth / 2 - 74.rpx,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: List.generate(
                3,
                (index) => Container(
                  height: 13.rpx,
                  width: 40.5.rpx,
                  margin:
                      EdgeInsets.symmetric(horizontal: index == 1 ? 13.rpx : 0),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(21.rpx),
                    color: const Color(0xffFA8303)
                        .withOpacity(currentPage == index ? 1.0 : 0.3),
                  ),
                ),
              ),
            ),
          ),
          Positioned(
            top: 63.rpx,
            right: 32.rpx,
            child: InkWell(
              onTap: () => AppTo.goto(context, const LoginPage()),
              child: Container(
                alignment: Alignment.center,
                width: 90.rpx,
                height: 48.rpx,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20.rpx),
                  border: Border.all(
                      color: Colors.white.withOpacity(0.88), width: 1.rpx),
                ),
                child: Text(
                  '跳过',
                  style: TextStyle(
                      fontSize: 18.rpx, color: Colors.white.withOpacity(0.88)),
                ),
              ),
            ),
          ),
          currentPage == 2
              ? Positioned(
                  bottom: 94.rpx,
                  left: HYSizeFit.screenWidth / 2 - 113.rpx,
                  child: InkWell(
                    onTap: () => AppTo.goto(context, const LoginPage()),
                    child: Container(
                      width: 226.rpx,
                      height: 65.rpx,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(33.rpx),
                      ),
                      child: Text(
                        '立即进入',
                        style: TextStyle(color: Colors.black, fontSize: 24.rpx),
                      ),
                    ),
                  ),
                )
              : const SizedBox.shrink(),
        ],
      ),
    );
  }
}
